package com.bw.contorller;

import com.bw.entity.Accountant;
import com.bw.service.AccountantService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class AccountantContorller {
    @Autowired
    AccountantService accountantService;
    //列表展示
    @RequestMapping("list")
    public String getList(Accountant accountant, Model model, @RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "3") Integer pageSize){
        PageInfo<Accountant> pg=accountantService.list(accountant,pageNum,pageSize);
        model.addAttribute("a",accountant);
        model.addAttribute("pg",pg);
        return "list";
    }
    //去添加
    @RequestMapping("toadd")
    public String toAdd(){
        return "add";
    }
    //执行添加
    @RequestMapping("add")
    public  String addAccountant(Accountant accountant){
        int i=accountantService.add(accountant);
        if(i>0){
            return "redirect:list";
        }
        return "add";
    }

    //ajax获取设计师分类
    @ResponseBody
    @RequestMapping("selectType")
    public List<Accountant> selectType(){
        List<Accountant> list=accountantService.selectType();
        return list;
    }

    //删除
    @ResponseBody
    @RequestMapping("deleteByid")
    public int deleteByid(Integer[] arr){
       int i= accountantService.deleteByid(arr);
       return i;
    }
}
